<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance(); 
	$sportDataArray = $ci->sport_entity->getArrayIdAndNameOfSport();	
		
	$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
?>


<div id="popupwindow" style="display:none;">
	<?php if(!isset($id) || $id == 0): ?>
		<form action="<?php echo site_url('admin/dataman/tournament/tournament_submit');?>" name="tournament_submit" id="tournament_submit" method="post" enctype="multipart/form-data" >
			
			<div class="grid2"><span class="bold">*Tournament Name:</span></div>
			<div class="grid6"><input type="text" maxlength="255" id="name" name="name" value="" class="std-input"/></div>
			<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Entry Fee:</span></div>
			<div class="grid6"><input type="text" maxlength="5" id="entry_fee" name="entry_fee" value="0" class="std-input"/> INR</div>
			<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Free Coins:</span></div>
			<div class="grid6"><input type="text" maxlength="5" id="free_coins" name="free_coins" value="10" class="std-input"/></div>
			<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*No. of Top Ranks:</span></div>
			<div class="grid6"><input type="text" maxlength="10" id="number_top_rank" name="number_top_rank" value="1000" class="std-input"/></div>
			<div class="grid2"><span class="bold red hidden" id="number_top_rank_error">Required field.</span></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Limit coins stake:</span></div>
			<div class="grid6"><input type="text" maxlength="10" id="limit_coin" name="limit_coin" value="-1" class="std-input"/> (-1 for unlimit)</div>
			<div class="grid2"><span class="bold red hidden" id="limit_coin_error">Required field.</span></div>
		
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Minimum coins stake:</span></div>
			<div class="grid6"><input type="text" maxlength="10" id="min_coin" name="min_coin" value="5" class="std-input"/></div>
			<div class="grid2"><span class="bold red hidden" id="min_coin_error">Required field.</span></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">Show Tournament Rank:</span></div>
			<div class="grid6"><input type="checkbox" id="show_tournament_rank" name="show_tournament_rank" value="1" checked="checked" /></div>
			
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">Show Weekly Rank:</span></div>
			<div class="grid6"><input type="checkbox" id="show_weekly_rank" name="show_weekly_rank" value="1" checked="checked" /></div>
			 
		<!--	
			<div class="clrboth"></div>
			<div class="grid2"><span class="bold">*Sport:</span></div>
			<div class="grid6"><?php /* echo form_dropdown( 'sport_id',
										$options = $sportDataArray,
										$selected = array(),
										"id='sport_id'"
									);*/	?></div>	
		-->							
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Start time:</span></div>
			<div class="grid6"><input type="text" maxlength="255" id="start_time" name="start_time" value="" class="std-input"/><button id="start_time_btn">choose</button></div>
			<div class="grid2"><span class="bold red hidden" id="start_time_error">Required field.</span></div>
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*End time:</span></div>
			<div class="grid6"><input type="text" maxlength="255" id="end_time" name="end_time" value="" class="std-input"/><button id="end_time_btn">choose</button></div>
			<div class="grid2"><span class="bold red hidden" id="end_time_error">Required field.</span></div>
			<div class="clrboth"></div>
			
			<div class="grid2"><span class="bold">*Description:</span></div>
			<div class="grid10">
				<textarea cols="85" rows="8" name="description" id="description" class="wysiwyg-advanced">
				</textarea>
			</div>
			<div class="grid2"><span class="bold red hidden" id="description_error">Required field.</span></div>
			<div class="clrboth"></div>
			
			<div class="grid2">&nbsp;</div>
			<div class="grid6"><input type="submit" class="button" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
			<div class="clrboth"></div>	
		
		</form>
<?php else:?>
	<form action="<?php echo site_url('admin/dataman/tournament/tournament_submit');?>" name="tournament_submit" id="tournament_submit" method="post" enctype="multipart/form-data" >
		<?php 
			$TOURNAMENT = $ci->tournament_entity->init('id',$id);
		?>
		
		<div class="grid2"><span class="bold">*Tournament Name:</span></div>
		<div class="grid6"><input type="text" maxlength="255" id="name" name="name" value="<?php echo $TOURNAMENT->getName();?>" class="std-input"/></div>
		<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
		
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Entry Fee:</span></div>
		<div class="grid6"><input type="text" maxlength="5" id="entry_fee" name="entry_fee" value="<?php echo $TOURNAMENT->getEntryFee();?>" class="std-input"/> INR</div>
		<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
		
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Free Coins:</span></div>
		<div class="grid6"><input type="text" maxlength="5" id="free_coins" name="free_coins" value="<?php echo $TOURNAMENT->getFreeCoins();?>" class="std-input"/></div>
		<div class="grid2"><span class="bold red hidden" id="name_error">Required field.</span></div>
		
		<div class="clrboth"></div>
			
		<div class="grid2"><span class="bold">*No. of Top Ranks:</span></div>
		<div class="grid6"><input type="text" maxlength="10" id="number_top_rank" name="number_top_rank" value="<?php echo $TOURNAMENT->getNumberTopRank();?>" class="std-input"/></div>
		<div class="grid2"><span class="bold red hidden" id="number_top_rank_error">Required field.</span></div>
		
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Limit coins stake:</span></div>
		<div class="grid6"><input type="text" maxlength="10" id="limit_coin" name="limit_coin" value="<?php echo $TOURNAMENT->getLimitCoin();?>" class="std-input"/> (-1 for unlimit)</div>
		<div class="grid2"><span class="bold red hidden" id="limit_coin_error">Required field.</span></div>
	
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Minimum coins stake:</span></div>
		<div class="grid6"><input type="text" maxlength="10" id="min_coin" name="min_coin" value="<?php echo $TOURNAMENT->getMinCoin();?>" class="std-input"/></div>
		<div class="grid2"><span class="bold red hidden" id="min_coin_error">Required field.</span></div>	
		
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">Show Tournament Rank:</span></div>
		<div class="grid6"><input type="checkbox" id="show_tournament_rank" name="show_tournament_rank" value="1" <?php if($TOURNAMENT->getShowTournamentRank() == 1) echo 'checked="checked"'; ?> /></div>
		
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">Show Weekly Rank:</span></div>
		<div class="grid6"><input type="checkbox" id="show_weekly_rank" name="show_weekly_rank" value="1" <?php if($TOURNAMENT->getShowWeeklyRank() == 1) echo 'checked="checked"'; ?> /></div>
		 
		<!--	
		<div class="clrboth"></div>
		<div class="grid2"><span class="bold">*Sport:</span></div>
		<div class="grid6"><?php /* echo form_dropdown( 'sport_id',
									$options = $sportDataArray,
									$selected = array($TOURNAMENT->getSportId()),
									"id='sport_id'"
								); */	?></div>	
		-->						
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Start time:</span></div>
		<div class="grid6"><input type="text" maxlength="255" id="start_time" name="start_time" value="<?php echo sysDateTimeFormat($TOURNAMENT->getStartTime());?>" class="std-input"/><button id="start_time_btn">choose</button></div>
		<div class="grid2"><span class="bold red hidden" id="start_time_error">Required field.</span></div>
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*End time:</span></div>
		<div class="grid6"><input type="text" maxlength="255" id="end_time" name="end_time" value="<?php echo sysDateTimeFormat($TOURNAMENT->getEndTime());?>" class="std-input"/><button id="end_time_btn">choose</button></div>
		<div class="grid2"><span class="bold red hidden" id="end_time_error">Required field.</span></div>
		<div class="clrboth"></div>
		
		<div class="grid2"><span class="bold">*Description:</span></div>
		<div class="grid10"><textarea cols="85" rows="8" name="description" id="description" class="wysiwyg-advanced"><?php echo $TOURNAMENT->getDescription();?></textarea></div>
		<div class="grid2"><span class="bold red hidden" id="description_error">Required field.</span></div>
		<div class="clrboth"></div>
		
		<input type="hidden" name="id" id="id" value="<?php echo $TOURNAMENT->getId();?>" />
		
		<div class="grid2">&nbsp;</div>
		<div class="grid6"><input type="submit" class="button" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
		<div class="clrboth"></div>	
	
	</form>
	
<?php endif;?>

</div>

<?php if($id != 0) :?>
	<script type="text/javascript">
		jQuery(document).ready(function() {
			jQuery('#popupwindow').dialog(
				{
					 width: 950,
					 resizable: false,
					 height:600,
					 title: 'Edit tournament' ,
					 close: function(event, ui) { 
						queryURL(window.location.pathname);
					 }
				}
			);
		});
	</script>
<?php endif;?>